function getCookie(name) {
    var start = document.cookie.indexOf(name + "="); //得到cookie字符串中的名称
    var len = start + name.length + 1; //得到从起始位置到结束cookie位置的长度
    //如果起始没有值且name不存在于cookie字符串中，则返回null
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null; //如果起始位置为-1也为null
    var end = document.cookie.indexOf(';', len); //获取cookie尾部位置
    if (end == -1) end = document.cookie.length; //计算cookie尾部长度
    return unescape(document.cookie.substring(len, end)); //获取cookie值
}


function getTypeId() {
    return location.search.split("=")[1]; // ?typeId=001
}

$(function () {
    let name = getCookie("name")
    if (name) {
        $("#token").html("欢迎您" + name).css({
            "color": "white",
            "font-size": "14px"
        })

    }

    $.get("http://10.35.161.229:81/prolist",{"typeId":getTypeId()},function(data){
        console.log("typeof data",typeof data);
        console.log("data",data);       
        let htmlStr="";

        data.forEach(goods => {
            htmlStr+=`
               <li>
                    <a href="Productdetails.html?id=${goods.Id}">
                    <div class="phonebox">
                        <p class="imglist"><img src="${goods.img}" alt=""></p>
                        <p class="phonename" >${goods.phonename}</p>
                        <p class="price"><b>￥${goods.price}</b>&nbsp;&nbsp;<span>多款选择</span></p>
                        <p class="lable"><span>赠送积分</span></p>
                        <p class="p-comment"><em class="peoplebuy"><span>${goods.phonenum}</span>人评价</em>&nbsp;&nbsp;&nbsp;<em class="haopin"><span>${goods.haoping}</span>%好评</em></p>
                    </div>
                    </a>
                </li>
            `;
        });
        $("#box").html(htmlStr);
    },"json")
})